{% extends 'basic.html' %}
{% block title %}修改课程{% endblock %}
{% block content %}
{% load static %}
<h3>修改课程</h3>
<form method="post">
    {% csrf_token %}
    <label for="course-name">课程名称：</label>
    <input type="text" id="course-name" name="course_name" value="{{ course.course_name }}" required>

    <label for="course-hours">课程课时：</label>
    <input type="number" id="course-hours" name="course_hours" value="{{ course.course_hours }}" required>

    <label for="course-point">课程学分：</label>
    <input type="number" id="course-point" name="course_point" value="{{ course.course_point }}" step="0.1" required>

    <label for="course-type">课程类型：</label>
    <select id="course-type" name="course_type">
        {% for type in course_types %}
        <option value="{{ type.type_id }}" {% if type.type_id == course.type_id %}selected{% endif %}>
            {{ type.type_name }}
        </option>
        {% endfor %}
    </select>

    <label for="course-status">课程状态：</label>
    <select id="course-status" name="course_status">
        <option value="开放公选" {% if course.course_status == '开放公选' %}selected{% endif %}>开放公选</option>
        <option value="暂不开放" {% if course.course_status == '暂不开放' %}selected{% endif %}>暂不开放</option>
        <option value="停止授课" {% if course.course_status == '停止授课' %}selected{% endif %}>停止授课</option>
    </select>

    <label>选课要求：</label>
    <div class="checkbox-group">
        {# 使用逗号包裹原始字符串，避免误匹配 #}
        {% with reqs=','|add:course.course_reqs|default:''|add:',' %}
        <label>
            <input type="checkbox" name="course_conditions" value="大三以上" 
                   {% if ',大三以上,' in reqs %}checked{% endif %}>
            大三以上
        </label>
        <label>
            <input type="checkbox" name="course_conditions" value="平时成绩80" 
                   {% if ',平时成绩80,' in reqs %}checked{% endif %}>
            平时成绩80
        </label>
        <label>
            <input type="checkbox" name="course_conditions" value="党员" 
                   {% if ',党员,' in reqs %}checked{% endif %}>
            党员
        </label>
        <label>
            <input type="checkbox" name="course_conditions" value="未拖欠学费" 
                   {% if ',未拖欠学费,' in reqs %}checked{% endif %}>
            未拖欠学费
        </label>
        {% endwith %}
    </div>

    <label for="course-memo">备注：</label>
    <textarea id="course-memo" name="course_memo">{{ course.course_memo }}</textarea>

    <label for="course-image">课程图片：</label>
    {% if course.course_textbook_pic %}
    <img src="data:image/png;base64,{{ course.course_textbook_pic }}" alt="教材封面" class="course-image">
    {% else %}
    <p>暂无图片</p>
    {% endif %}
    <input type="file" id="course-image" name="course_image" accept="image/*">

    <button type="button" id="save-btn">保存修改</button>
    <button type="button" id="cancel-btn">放弃更改</button>
</form>
<body data-course-no="{{ course.course_no }}">
    <script src="{% static 'js/edit_course.js' %}"></script>
</body>
<link rel="stylesheet" href="{% static 'css/edit_course.css' %}">
{% endblock %}